const array = [1, 2, 3, 4, 5, 6, 7]
// const array_2 = [{
//   children: [{
//     children: [{ router: "workplace", apiUrl: 8 }],
//     router: "dashboard",
//   },
//   {
//     children: [{ router: "user", apiUrl: 11 }, { router: "roles", apiUrl: 15 }, { router: "roles", apiUrl: 1 }],
//     router: "authority",
//   },
//   {
//     children: [{ router: "user", apiUrl: 31 }, { router: "roles", apiUrl: 11 }],
//     router: "authority",
//   }],
//   router: 'root'
// }]
const array_2 = [{
  children: [{ router: "workplace", apiUrl: 8 }],
  router: "dashboard",
},
{
  children: [{ router: "user", apiUrl: 11 }, { router: "roles", apiUrl: 15 }, { router: "roles", apiUrl: 1 }],
  router: "authority",
},
{
  children: [{ router: "user", apiUrl: 31 }, { router: "roles", apiUrl: 11 }],
  router: "authority",
}]

// });
// 过滤路由的函数
function filterRouter(array, array_2) {
  array_2.map((item) => {
    item.children.map((childItem, childIndex) => {
      if (array.indexOf(childItem.apiUrl) < 0) {
        item.children.splice(childIndex, 1, null)
      }
    })
    item.children = item.children.filter(item => item)
  })
  const newArray = array_2.filter((item) => item.children.length !== 0)
  return newArray
}
// const aad = array_2.
console.log(JSON.stringify(filterRouter(array, array_2)));
// array_2.forEach((item, index) => {
//   if (item.children.length === 0) array_2.splice(index, 1)
// })
// console.log(array_2);